function y = sosfilter(b,a,x)

global M;
global N;
bq = round((2^(N-1)-1)*b) ./ 2^(N-1);
aq = round((2^(N-1)-1)*a) ./ 2^(N-1);

c = 0;
c(1) = x(1);
y(1) = round(2^(M-1) * bq(1) * c(1)) / 2^(M-1);
c(2) = x(2) - round(2^(M-1)*aq(2) * c(1)) ./ 2^(M-1);
y(2) = round(2^(M-1)*bq(1) * c(2)) / 2^(M-1) + round(2^(M-1)*bq(2) * c(1)) / 2^(M-1);
for n = 3:length(x)
c(n) = x(n) -  round(2^(M-1)*aq(2) * c(n-1)) / 2^(M-1) - round(2^(M-1)*aq(3) * c(n-2)) / 2^(M-1);
y(n) = round(2^(M-1)*bq(1) * c(n)) / 2^(M-1) + round(2^(M-1)*bq(2) * c(n-1)) / 2^(M-1) + round(2^(M-1)*bq(3) * c(n-2)) / 2^(M-1);
end

 


